Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #264 #268

Merged
merged 5 commits into from
Sep 29, 2024
Merged

Fixes #264 #268

merged 5 commits into from
Sep 29, 2024

Conversation

Mark104
Copy link
Contributor

@Mark104 Mark104 commented Sep 22, 2024

Implemented as a dropdown option on a bot participant as shown below, requires validation by @drivver44 as if he feels this is enough for now (perhaps last added AI right click could be an additional issue built from this?).

image

Two watchouts:

  • Needs testing on an online lobby, this is currently only tested in custom singleplayer (only just started contributing so not fully setup yet!).
  • Has been implemented with a json stringify/parse which should handle nested objects correctly, if these objects are just data models (no methods).

Please feel free to let me know if any of this is incorrect or if I can do anything better, this is my first contribution for this project and felt I could add a very little bit of value with a simple issue.

With a watchout, a json duplication may not be the best way to do this with typescript as it assumes this object is a data model.
@@ -59,6 +63,13 @@ function kickBot() {
props.battle.removeBot(props.bot);
}

// Duplicates this bot and its settings and gives it a new player id.
function duplicateBot() {
let duplicatedBot = JSON.parse(JSON.stringify(props.bot));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structuredClone should be cleaner in what you are trying to do here vs pasing object via JSON serialization. It also should be better for typing.

Also change let to const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Adjustments made in a877be / 959a9fc, alongside a fix for options not being set by some sort of Id.

…e rather than playerId (resulting in the abiltiy to not uniquely set options for susequent bots).
Comment on lines 93 to 105
// Returns a bot by it's PlayerId. Returns undefined if not found..
public getBotParticipantByPlayerId(playerId: number): User | Bot | undefined {
return this.participants.value.find((participant) => {
const isBot = !("userId" in participant);
if (isBot) {
if (participant.playerId === playerId) {
return true;
}
}
return false;
});
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should .find on this.bots instead of this.participants, then you can remove User from the return type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

Addressed in 7bcc76.

@@ -90,6 +90,16 @@ export abstract class AbstractBattle<T extends BattleOptions = BattleOptions> {
});
}

// Returns a bot by it's PlayerId. Returns undefined if not found..
public getBotByPlayerId(playerId: number): Bot | undefined {
return this.bots.find((bot) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been just (bot) => bot.playerId === playerId but whatever.

@p2004a p2004a merged commit 3f43ec2 into beyond-all-reason:master Sep 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants